export default {
    computed: {
        user() {
            return this.$store.state.user.data
        }
    },
    data() {
        return {
            userIoListColumns: [{
                'title': '订单号',
                'align': 'center',
                'key': 'record_no',

            }, {
                'title': '用户',
                'align': 'center',
                'key': 'nickname',

            },{
                'title': '手机号',
                'align': 'center',
                'key': 'mobilenum',

            }, {
                'title': '收支类型',
                'align': 'center',
                'key': 'record_type',
                'width': 90
            },  {
                'title': '收支数量',
                'align': 'center',
                'key': 'love_beans_num',
                'width': 90
            },  {
                'title': '时间',
                'align': 'center',
                'key': 'createtime',
                'width': 200

            }, {
                'title': '剩余爱豆',
                'align': 'center',
                'key': 'rest_love_beans',
                'width': 100
            }],
            searchKey: '',
            pageCount: 0,
            pageNum: 1,
            pageLoading: false,
            showModal: false,
            modalLoading: true,
            userIoList: []
        }
    },
    methods: {
        /**
         * @param {Boolean} type
         * 设置确定按钮loading动画，传True或者False
         */
        changeLoadingStatus(type) {
            if (!type) {
                this.modalLoading = false;
            }
            this.$nextTick(() => {
                this.modalLoading = true;
            });
        },
        doSearch() {
            this.pageNum = 1;
            this.getUserIoListList();
        },
        clearSearch() {
            this.searchKey = '';
            this.pageNum = 1;
            this.getUserIoListList();
        },
        changePage(num) {
            this.pageNum = num;
            this.getUserIoListList();
            document.querySelector('.single-page-con').scrollTo(0, 0)
        },
        getUserIoListList() {
            if (this.pageLoading) return
            this.pageLoading = true;
            this.http.post(this.postUrl.getUserIoListUrl, {
                token: this.user.tokenList[0],
                pageNum: this.pageNum,
                pageSize: 20,
                key_word: this.searchKey
            }).then((data) => {
                console.log(data);
                if (data.code > -1) {
                    this.pageCount = data.data.totalRow;
                    this.userIoList = JSON.parse(JSON.stringify(data.data.list));
                } else {
                    this.errorHandle(data.msg)
                }
            }, () => {
                this.errorHandle()
            }).then(() => {
                this.pageLoading = false;
            })
        },

    },
    created() {
        this.userIoListColumns.forEach(item => {
            if (item.key === 'pay_method') {
                item.render = (h, param) => {
                    let payText = '';
                    switch (param.row.pay_method) {
                        case '0':
                            payText = '公众号支付'
                            break;
                        case '1':
                            payText = '微信支付'
                            break;
                        case '2':
                            payText = '支付宝'
                            break;
                        case '3':
                            payText = '爱豆支付'
                            break;
                    }
                    return h("span", payText);
                };
            }
            if (item.key === 'record_type') {
                item.render = (h, param) => {
                    let stateText = '';
                    switch (param.row.record_type) {
                        case '0':
                            stateText = '消费'
                            break;
                        case '1':
                            stateText = '充值'
                            break;
                        case '2':
                            stateText = '其他收入'
                            break;
                    }
                    return h("span", stateText);
                };
            }
        })
        if (this.user) {
            this.getUserIoListList()
        }
    },
    watch: {
        user(val, old) {
            if (!old && val) {
                this.getUserIoListList()

            }
        },
    }
}
